package org.easy.tool.res;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description: 请求返回同意封装
 * @Author: wxl
 * @CreateTime: 2022/12/28 8:46
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public static <T> Result<T> success(){
        return new Result<>(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMessage(),null);
    }

    public static <T> Result<T> success(T data){
        return new Result<>(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMessage(),data);
    }

    public static <T> Result<T> success (String message,T data) {
        return new Result<>(ResultEnum.SUCCESS.getCode(),message,data);
    }

    public static Result<?> failed () {
        return new Result<>(ResultEnum.FAIL.getCode(),ResultEnum.FAIL.getMessage(),null);
    }

    public static Result<?> failed (String message) {
        return new Result<>(ResultEnum.FAIL.getCode(),message,null);
    }

    public static Result<?> failed (IResult iResult) {
        return new Result<>(iResult.getCode(), iResult.getMessage(), null);
    }

    public static <T> Result<T> instance (Integer code,String message,T data) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

}
